package server;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.concurrent.ThreadPoolExecutor;

import service.Service;

public class ServerSocketProcessor extends Thread{
	
    private Service service;
    private ThreadPoolExecutor threadPoolExecutor;

    public ServerSocketProcessor(Service service, ThreadPoolExecutor threadPoolExecutor) {
        this.service = service;
        this.threadPoolExecutor = threadPoolExecutor;
    }

    public ServerSocketProcessor() {
    }


    @Override
    public void run() {
        Integer port = service.getPort();
        try {
            ServerSocket serverSocket = new ServerSocket(port);
            while (true){
                Socket socket = serverSocket.accept();
                RequestProcessorNew requestProcessor = new RequestProcessorNew(socket,service);
                threadPoolExecutor.execute(requestProcessor);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
}
